message <- "So long and thanks for all the fish"
year <- 2025
the_answer <- 42.5
earth_demolished <- FALSEA value is a basic unit of stuff that a program works with.
Values are allowed to have different data types:
are names that refer to values.
A variable is like a container that holds something - when you refer to the container, you get whatever is stored inside.
We assign values to variables using the syntax object_name <- value.
every element has the same data type
Vector: a one-dimensional column of homogeneous data.
Matrix: the next step after a vector - it’s a set of homogenous data arranged in a two-dimensional, rectangular format.
elements can be of different types
List: a one-dimensional column of heterogeneous data.
Dataframe: a two-dimensional set of heterogeneous data arranged in a rectangular format.
We use square brackets ([]) to access elements within data structures.
We can combine logical statements using and, or, and not.
(X AND Y) requires that both X and Y are true.
(X OR Y) requires that one of X or Y is true.
(NOT X) is true if X is false, and false if X is true.
seq(from = 1, to = 10, by = 1
Error in parse(text = input): <text>:2:0: unexpected end of input
1: seq(from = 1, to = 10, by = 1
^
seq(from = 1, to = 10 by = 1)
Error in parse(text = input): <text>:1:23: unexpected symbol
1: seq(from = 1, to = 10 by
^
sequence(from = 1, to = 10, by = 1)
Error in sequence.default(from = 1, to = 10, by = 1): argument "nvec" is missing, with no default
sqrt(“1”)
my_obj(5)
Error in my_obj(5): could not find function "my_obj"
Just because you see scary red text, this does not mean something went wrong! This is just R communicating with you.
Often, R will give you a warning.
This means that your code did run…
…but you probably want to make sure it succeeded.
If the word Error appears in your message from R, then you have a problem.
This means your code could not run!
Error: Object
some_objnot found.
It probably means…
You haven’t run the code to create
some_objOR you have a typo in the name!
Error: Object of type ‘closure’ is not subsettable.
It probably means…
Oops, you tried to use square brackets on a function.
Error: Non-numeric argument to binary operator.
It probably means…
You tried to do math on data that isn’t numeric.
Look at the help file for the function! (e.g., ?group_by)
When all else fails, Google your error message or ask ChatGPT!
Leave out the specifics.
Include the name(s) of the function(s) you are using.
What’s wrong here?
Error in matrix(c("a", "b", "c", "d"), num_row = 2): unused argument (num_row = 2)
The documentation says…
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE,
dimnames = NULL)
File > New File > R Script) are files of code that are meant to be run on their own.Scripts can be run in RStudio by clicking the Run button at the top of the editor window when the script is open.
You can also run code interactively in a script by:
highlighting lines of code and hitting run.
placing your cursor on a line of code and hitting run.
placing your cursor on a line of code and hitting ctrl + enter or command + enter.
Notebooks are an implementation of literate programming.
They allow you to integrate code, output, text, images, etc. into a single document.
E.g.,
We love notebooks because they help us produce a reproducible analysis!
Markdown is a markup language.
It uses special symbols and formatting to make pretty documents.
Markdown files have the .md extension.
Quarto unifies and extends the R Markdown ecosystem.
Quarto files have the .qmd extension.
Consistent implementation of attractive and handy features across outputs:
More accessible defaults and better support for accessibility.
Guardrails that are helpful when learning:
Support for other languages like Python, Julia, Observable, and more.
Quarto makes moving between outputs straightforward.
How does Quarto know that a section of text should be interpreted as R code?
R code chunk options are included at the top of each code chunk, prefaced with a #| (hashpipe).
To take your .qmd file and make it look pretty, you have to render it.
Quarto CLI (command line interface) orchestrates each step of rendering:
knitr or jupyter.When you click Render: